<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>10-$工具方法</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
    <script>
        $(() => {

            /**
             * 知识点：
             * 1. $.each(): 遍历数组或对象中的数据
             * 2. $.trim(): 去除字符串两边的空格
             * 3. $.type(obj): 得到数据的类型
             * 4. $.isArray(obj): 判断是否是数组
             * 5. $.isFunction(obj): 判断是否是函数
             * 6. $.parseJSON(json): 解析 json 字符串转换为 js 对象/数组
            */

            const obj = {
                name: 'Tom',
                setName: function (name) {
                    this.name = name
                }
            }
            $.each(obj, (key, value) => {
                console.log(key, value)
            })

            console.log($.type(obj))        // object
            console.log($.type($))          // function

            console.log($.isArray($('body')))       // false
            console.log($.isArray([]))              // true

            console.log($.isFunction($))            // true

            const json1 = '{ "name": "Tom", "age": 12 }'
            console.log($.parseJSON(json1))

            const json2 = '[{"name": "Tom", "age": 12}, {"name": "JACK", "age": 13}]'
            console.log($.parseJSON(json2))

        })
    </script>
</head>

<body>

</body>

</html>